//
//  DishVideoView.m
//  XRmenu
//
//  Created by gaomz on 11-3-22.
//  Copyright 2011 E0571. All rights reserved.
//

#import "DishVideoView.h"
#import "VideoPlayer.h"
#define kTagOfMediaPlayer 190
#define kTagOfVideoClose 110

@implementation DishVideoView



-(id)initWithViewName:(NSString *)vname product:(Product *)product
{
	NSDictionary* aDic = [self findNode:APPSESSION.allconfig withKey:vname];
	if ((self=[super initWithConfig:aDic])) {
		[self add1fingerLeftSwipe];
		[self add1fingerRightSwipe];
		[self add1fingerTopSwipe];
		[self add1fingerDownSwipe];
		
		vProduct = [product retain];
		
		UILabel *lbTitle = (UILabel *)[self viewWithTag:kTagOfStartLabel];
		[lbTitle setTextAlignment:UITextAlignmentCenter];
		[lbTitle setText:[XRmenuPublic jsonfield:product.pName]];

		[self playVideo];
				
	}
	return self;
}

-(void)playVideo
{
	XRmenuError *error=nil;
	NSString *videoFileName=[XRmenuPublic haveVedioFile:vProduct Error:&error];
	if (!error) {
		VideoPlayer *player = (VideoPlayer *)[self viewWithTag:kTagOfMediaPlayer];
		[player setPlayerUrl:videoFileName];
		[player playVideo];
	}

}

#pragma mark 按钮点击事件
-(void) buttonClicked:(id)sender
{


	NSInteger tag=[sender tag];
	switch (tag) {
		case kTagOfVideoClose:
			[self removeFromSuperview];
			break;
		default:
			break;
	}
}

#pragma mark 手势操作
- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)recognizer {
	
}

- (void)handleSwipeRight:(UISwipeGestureRecognizer *)recognizer {
	
}

-(void)handleSwipeTop:(UISwipeGestureRecognizer *)recognizer
{
	
}
-(void)handleSwipeDown:(UISwipeGestureRecognizer *)recognizer
{
	
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code.
}
*/

#pragma mark 语言切换
-(void) changeLanguage:(NSNotification *)notification
{
	// todo: 切换语言
	NSDictionary *dict = [APPSESSION.allconfig findAtPath:[NSString stringWithFormat:@"UI Skin/%@/Dish Main View/Dish Photo View/Dish Video View", APPSESSION.uistyle]];
	if (dict) {
		NSArray *bts = (NSArray*)[dict objectForKey:@"button list"];
		[self translateButtons:bts];
	}
	
}


-(void)dealloc
{
	[vProduct release];
	[super dealloc];
}

@end
